<?php


namespace app\api\model;


use app\common\model\Category;
use think\Model;

class PackageGoods extends Model
{
    // 表名
    protected $name = 'express_package_goods';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;
    // 追加属性
    protected $append = [
        'category_name',
    ];

    public function getCategoryNameAttr($value, $data)
    {
        if($data['category_id']){
            return Category::where(['id'=>$data['category_id']])->value('name');
        }
        return '';
    }
}